<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="员工姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
<!--              <a-input :disabled=formDisabled v-model="model.userId" placeholder="请输入员工id"  ></a-input>-->
              <select-user-by-dep :disabled=formDisabled  :multi="false"
                                  v-model="model.userId"   @back="selectPeople"></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="员工编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employeeNo">
              <a-input :disabled=formDisabled v-model="model.employeeNo" disabled placeholder="请输入员工编号" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="员工性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gender">
              <j-dict-select-tag :disabled=formDisabled type="list"  v-model="model.gender"
                                 dictCode="gender"
                                 placeholder="员工性别" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入职日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="joinDate">
              <j-date :disabled=formDisabled placeholder="入职日期" v-model="model.joinDate" :show-time="true"
                      date-format="YYYY-MM-DD" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加入日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="joinTime">
              <j-date :disabled=formDisabled placeholder="加入日期" v-model="model.joinTime" :show-time="true"
                      date-format="YYYY-MM-DD" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
          <a-form-model-item label="所在岗位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainPost">
            <j-dict-select-tag :disabled=formDisabled type="list"  v-model="model.mainPost"
                               dictCode="sys_position,name,id"
                               placeholder="所在岗位" disabled/>
          </a-form-model-item>
        </a-col>
          <a-col :span="24">
          <a-form-model-item label="审批状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus" v-if="false">
            <a-input :disabled=formDisabled v-model="model.auditStatus"    ></a-input>
          </a-form-model-item>
        </a-col>


        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import moment from 'moment';
  export default {
    name: 'ErpOmcTeamManagerMemberForm',
    components: {
      SelectUserByDep
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
          userId:[{ required: true, message: '请输入员工姓名!'}],
        },
        url: {
          add: "/api/erp/omc/teammanager/erpOmcTeamManagerMember/add",
          edit: "/api/erp/omc/teammanager/erpOmcTeamManagerMember/edit",
          queryById: "/api/erp/omc/teammanager/erpOmcTeamManagerMember/queryById",
          queryFileById: '/api/erp/files/employee/erpEmployeeFile/queryFileById',
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      selectPeople(data) {
          //查询人员信息
        let params = { id: this.model.userId };
        getAction(this.url.queryFileById, params).then((res) => {
          if (res.success) {
            this.$set(this.model, 'mainPost', res.result.mainPost)
            this.$set(this.model, 'gender', res.result.gender)
            this.$set(this.model, 'employeeNo', res.result.employeeNo)
            this.$set(this.model, 'joinDate', res.result.joinDate)
          }
        });
      },
      add () {
        this.edit(this.modelDefault);
        this.model.joinTime = moment().format('YYYY-MM-DD');
      },
      edit (record) {
        Object.assign(this.$data, this.$options.data())
        // this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            //debugger;
            if (!this.model.id) {
              this.model.id = parseInt(Math.random() * 1000000000000);
              this.model.auditStatus = '0'
            }
            that.$emit('ok', this.model);
          }
        })
      },
    }
  }
</script>
